package com.ky.homestay.config;

import javax.annotation.PostConstruct;

@Order(Ordered.LOWEST_PRECEDENCE)
@DependsOn(value = {"springUtil", "redisUtils"})
@Component
public class HomestayInit {
    @Autowired
    private DataSource dataSource;

	@PostConstruct
	public void initFreeMarkStaticPage() throws SQLException {
        //创建文件夹
        initFolder();

        //服务器台数初始化
        initServerWorkId();

    }

    /**
     * 初始化文件夹
     */
    private void initFolder(){

    }

    /**
     * 获取服务器获取的顺序号
     */
    private void initServerWorkId(){
        long workerId = RedisUtils.incr(RedisConstant.SERVER_WORKERID,1);
        ErpConstant.ConstantVariable.SERVER_WORKERID = (int)workerId % ErpConstant.SERVER_COUNT;
        //创建需要依赖服务器号的对象或bean
        IdTool.snowflake = new SnowflakeUtil(ErpConstant.ConstantVariable.SERVER_WORKERID);
    }
}
